<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        销安管理-项目信息
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../../css/bootstrap.css">
    <link rel="stylesheet" href="../../../lib/layui/css/layui_2.5.7.css">
    <style>
        .layui-table-page select {
            height: 22px;
        }
    </style>
</head>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>销安管理</cite></a>
            <a><cite>项目信息</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
            href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">

        <div class="main_box">
            <div class="panel-heading">
                <ul class="nav nav-tabs" id="navTabs">
                    <li class="active"><a class="receivePane" data-tab="" href="engineer_marketingsafetymanagement.html">在跟项目</a></li>
                    <li class=""><a class="payPane" data-tab="" href="engineer_already_give_up_pro.html">已放弃项目</a></li>
                    <li style="float: right;width: 162px" class="dropdown">
                        <button class="layui-btn" onclick="admin_add('添加项目','project_add.html')"><i
                                class="layui-icon">&#xe608;</i>添加</button>
                    </li>
                </ul>
            </div>
        </div>

        <form class="layui-form x-center">
            <div class="layui-form-pane" style="margin-top: 5px;">
                <div class="layui-form-item" style="padding-left: 3%">
                    <label class="layui-form-label">项目名称</label>
                    <div class="layui-input-inline">
                        <select name="projectId" id="projectId" lay-search="">
                            <option value="">选择项目</option>
                        </select>
                    </div>

                    <label class="layui-form-label">客户名称</label>
                    <div class="layui-input-inline">
                        <select name="customerId" lay-search="" id="customerId">
                            <option value="">选择客户</option>
                        </select>
                    </div>

                    <label class="layui-form-label">项目级别</label>
                    <div class="layui-input-inline">
                        <select name="projectLevel" lay-search="" id="projectLevel">
                            <option value="">选择项目级别</option>
                            <option value="1">普通</option>
                            <option value="2">重要</option>
                        </select>
                    </div>

                    <!-- <label class="layui-form-label">业务类型</label>
                    <div class="layui-input-inline">
                        <select name="businessTypeId" lay-search="">
                            <option value="">选择业务类型</option>
                            <option value="1">销售项目</option>
                            <option value="2">工程项目</option>
                        </select>
                    </div> -->
                    <hr>
                    <label class="layui-form-label">所属阶段</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" class="layui-input" name="belongStage" placeholder="所属阶段">
                    </div>
                    <label class="layui-form-label">添加日期</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  class="layui-input" placeholder="开始时间" name="startTime" id="startTime">
                    </div>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  class="layui-input" placeholder="截止时间" name="endTime" id="endTime">
                    </div>
                    <div class="layui-input-inline layui-show-xs-block">
                        <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <button type="reset" class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe666;</i>重置
                        </button>
                    </div>

                </div>
            </div>
        </form>

        <div class="layui-card-body">

            <table class="layui-table" id="test" lay-filter="test">
            </table>
        </div>


    </div>
    <script type="text/html" id="barDemo">
        <a title="放弃" lay-event="giveUp_pro" class="ml-5 layui-btn-xs layui-btn layui-btn-warm" >放弃</a>
    </script>

    <script type="text/javascript" src="../../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../../js/myAjax.js"></script>
    <script type="text/javascript" src="../../../js/pub.js"></script>
    <script type="text/javascript" src="../../../lib/layui/layui2.5.7.js"></script>
    <script src="../../../js/x-layui.js" charset="utf-8"></script>
    <script>
        layui.use(['laydate', 'element', 'laypage', 'layer', 'form'], function () {
            $ = layui.jquery;//jquery
            laydate = layui.laydate;//日期插件
            lement = layui.element;//面包导航
            laypage = layui.laypage;//分页
            layer = layui.layer;//弹出层
            var form = layui.form;
            okLoading.close($);
        });
    </script>



    <script>

        layui.use(['laydate', 'element', 'laypage', 'layer','table', 'form'], function () {
            $ = layui.jquery;//jquery
            laydate = layui.laydate;//日期插件
            lement = layui.element;//面包导航
            laypage = layui.laypage;//分页
            layer = layui.layer;//弹出层
            table = layui.table;
            var form = layui.form;
            okLoading.close($);

            getCustomer();
            getProject();

            //执行一个laydate实例
            laydate.render({
                trigger: 'click',
                type: 'datetime',
                elem: '#startTime' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                trigger: 'click',
                type: 'datetime',
                elem: '#endTime' //指定元素
            });

            //方法级渲染
            var t1 = table.render({
                elem: '#test',
                url: $baseUrl + 'xa/project/findListByPage',
                where: {
                    userId: $userId,
                    businessTypeId:2,
                    delFlag: 0
                },
                headers: {
                    token: $token
                }
                , toolbar: '#toolbarDemo',

                // toolbar: true,
                cols: [
                    [
                        {
                            // field: 'id',
                            type:'numbers',
                            title: '序号',
                        },
                        {
                            field: 'name',
                            title: '项目名称',
                            event: 'project_info',
                            style: 'color: #145CCD;'
                        },
                        {
                            field: 'customerName',
                            title: '客户名称',
                            event: 'customer_info',
                            style: 'color: #145CCD;'
                        },
                        {
                            field: 'projectLevel',
                            title: ' 项目级别',
                            templet(item) {
                                if (item.projectLevel === 1) {
                                    return '<span>普通</span>';
                                } else {
                                    return '<span>重要</span>';
                                }

                            }
                        },
                        {
                            field: 'belongStage',
                            title: '跟踪阶段',
                        },
                        // {
                        //     field: 'repaymentUnit',
                        //     title: '工程进度',
                        // },
                        {
                            // field: 'typeOfPayment',
                            title: '项目地址',
                            width: '30%',
                            templet(item) {
                                if (item.addressProvince != null) {
                                    return item.addressProvinceName+','+item.addressCityName+','+item.addressAreaName+','+item.address;
                                } else {
                                    return '';
                                }

                            }
                        },
                        {
                            field: 'businessTypeId',
                            title: '业务合作',
                            templet(item) {
                                if (item.businessTypeId === 1) {
                                    return '<span>销售项目</span>';
                                } else {
                                    return '<span>工程项目</span>';
                                }

                            }
                        },
                        {
                            field: 'createTime',
                            title: '添加时间',
                            sort:true
                        },
                        {
                            field: 'status',
                            title: '操作',
                            width: '5%',
                            templet: '#barDemo',

                        }]
                ],
                request: {
                    pageName: 'pageNum', //页码的参数名称，默认：page
                    limitName: 'pageSize',
                },
                response: {
                    statusName: 'code' //规定数据状态的字段名称，默认：code
                    ,
                    statusCode: 0 //规定成功的状态码，默认：0
                    ,
                    msgName: 'msg' //规定状态信息的字段名称，默认：msg
                    ,
                    countName: 'total' //规定数据总数的字段名称，默认：count
                    ,
                    dataName: 'data', //规定数据列表的字段名称，默认：data
                },
                id: 'test',
                page: true,
                height: 'auto',
                even: true,
                done: function (res, curr, count) {
                    //是否有权限或权限是否失效
                    // authorizeState();
                    // console.log(res);
                }
            });


            form.on('submit(sreach)', function(data) {
                var projectId = data.field.projectId;
                var customerId = data.field.customerId;
                var projectLevel = data.field.projectLevel;
                var businessTypeId = 2;

                var belongStage = data.field.belongStage;
                var startTime = data.field.startTime;
                var endTime = data.field.endTime;

                table.reload('test', {
                    where: { //设定异步数据接口的额外参数，任意设
                        projectId: projectId,
                        customerId: customerId,
                        projectLevel: projectLevel,
                        businessTypeId:businessTypeId,
                        belongStage: belongStage,
                        startTime: startTime,
                        endTime: endTime,
                    },
                });
                return false;
            })

            //监听工具条
            table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                let data = obj.data; //获得当前行数据
                let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                if (layEvent === 'del') { //删除
                    layer.confirm('是否确认删除 【' + data.id + '】 ？', {
                        icon: 3,
                        title: '提示'
                    }, function (index) {
                        let request = {
                            url:"/borrowAndReturnWater/delBorrowAndReturnWater/"+data.id,
                            data: {
                                userId: $userId,
                            },
                            method: "delete",
                        };
                        sendRequest(request, (data) => {
                            if (data.code === 0) {
                                layer.msg("删除成功", {
                                    icon: 1
                                });
                                t1.reload();
                            } else {
                                layer.msg("删除失败，请稍后再试！", {
                                    icon: 5
                                });
                            }
                        });
                        layer.close(index);
                    });
                }
                // else if (layEvent === 'view') { //编辑
                //     x_admin_show('编辑用户', 'LoanFlowedit.html?recordId=' + data.id,"1200","600")
                // }
                else if(layEvent === 'project_info'){

                    x_admin_show('项目详情', 'essential_information/essential_information.html?recordId=' + data.id + '&businessTypeId=' + data.businessTypeId,"1200","600")
                }else if(layEvent === "customer_info"){
                    x_admin_show('客户详情', 'customer_update.html?recordId=' + data.customerId,"1200","600")
                }else if (layEvent === 'giveUp_pro') { //放弃项目
                    if (data.delFlag === -1) {
                        layer.msg("项目已放弃，不能重复操作！", {
                            icon: 7
                        });
                    } else {
                        admin_add('确认放弃？', 'give_up_pro.html?proId=' + data.id)
                    }

                }
            });

        });

        function getCustomer(){
            $.ajax({
                type:"get",
                url:baseHead + "xa/customer/list",
                data:{
                    userId :$userId
                },
                headers: {
                    "token": $token,
                },
                success:function(res){
                    if(res.code === 0){
                        for(var i =0;i < res.data.length;i++){
                            $("#customerId").append("<option value=\""+res.data[i].id+"\">"+res.data[i].name+"</option>");
                        }
                        //重新渲染
                        layui.form.render("select");
                    }else{
                        layer.msg(res.message);
                    }
                }
            });
        }

        function getProject(){
            // document.getElementById("projectId").innerHTML = "";
            $.ajax({
                type:"get",
                url:baseHead + "xa/project/findByDelFlag",
                data:{
                    userId :$userId,
                    delFlag: 0
                },
                headers: {
                    "token": $token,
                },
                success:function(res){
                    if(res.code == 0){
                        // $("#projectId").append("<option value=''>请选择关联项目</option>");
                        for(var i =0;i < res.data.length;i++){
                            $("#projectId").append("<option value=\""+res.data[i].id+"\">"+res.data[i].name+"</option>");
                        }
                        //重新渲染
                        layui.form.render("select");
                    }else{
                        layer.msg(res.message);
                    }
                }
            });
        };


        function reload(value) {
            table.reload('test', {
                where: {
                    remark: $("input[name=remark]").val(),
                    typeOfPayment: $("input[name=typeOfPayment]").val(),
                    repaymentUnit: $("input[name=repaymentUnit]").val(),

                }
            });
        }

        function admin_add(title,url,w,h){
        x_admin_show(title,url,w,h);
    }
    </script>
</body>

</html>
